package com.rr.springcloud.controller;

import com.rr.springcloud.pojo.Payment;
import com.rr.springcloud.service.PaymentService;
import com.rr.springcloud.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * @author RR
 * @date 2021/3/14 23:45
 */
@Controller
public class PaymentController {

    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String port;

    @PostMapping("/payment/create")
    @ResponseBody                   //这里入参记得添加@RequestBody注解！！！！
    public ResultVo<Payment> create(@RequestBody Payment payment) {
        int i = paymentService.insertPayment(payment);
        System.out.println(payment);
        if (i > 0) {
            return new ResultVo(200, "插入成功,port:" + port, payment);
        }else {
            return new ResultVo(400, "插入失败,port:" + port, payment);
        }
    }

    @GetMapping("/payment/get/{id}")
    @ResponseBody
    public ResultVo getPayment(@PathVariable("id") Long id) {
        Payment payment = paymentService.findById(id);
        System.out.println(payment);
        if (payment != null) {
            return new ResultVo(200, "查询成功,port:" + port, payment);
        }else {
            return new ResultVo(400, "查询失败,port:" + port, payment);
        }
    }
}
